{{ template "head" .Global}}

<!--DataTables example-->
<div id="table-datatables">
    <h4 class="header">用户列表 <a href="#adduser"
                               class="btn dropdown-button waves-effect waves-light modal-trigger"
                               style="float:right">添加</a>
    </h4>
    <div class="row">
        <div class="col s12 m12 l12">
            <table id="data-table-simple" class="responsive-table display" cellspacing="0">
                <thead>
                <tr>
                    <th>用户ID</th>
                    <th>用户名</th>
                    <th>用户组</th>
                    <th>电话</th>
                    <th>邮箱</th>
                    <th>操作</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                {{ range $k,$v :=$.LdapUserAll}}
                <tr>
                    <td>{{$v.uid}}</td>
                    <td>{{$v.displayName}}</td>

                    {{ if eq $v.gidNumber "0"}}
                    <td>未加入任何组</td>
                    {{ else }}
                    {{ range $k1,$v1 :=$.LdapGroupAll}}
                    {{ if eq $v.gidNumber $v1.gidNumber}}
                    <td>{{$v1.description}}</td>
                    {{ end }}
                    {{ end }}
                    {{ end }}


                    <td>{{$v.mobile}}</td>
                    <td>{{$v.mail}}</td>
                    <td>
                        <a href="#" class="btn dropdown-button waves-effect waves-light "
                           onclick="ldap_rese_passwd({{$v.uid}},{{$v.mail}})">重置密码</a>
                        <a href="#edituser"
                           class="btn dropdown-button waves-effect waves-light"
                           onclick="ldap_user_edit_value({{$v.uid}},{{$v.givenName}},{{$v.sn}},{{$v.gidNumber}},{{$v.mobile}},
                                   {{$v.mail}})">编辑</a>

                        <a href="#" class="btn dropdown-button waves-effect waves-light "
                           onclick="ldap_user_sshkey_value({{$v.uid}},{{$v.sshPublicKey}})">SSHKEY管理</a>
                        <a href="#" class="btn dropdown-button waves-effect waves-light " onclick="ldap_user_hosts_value({{$v.uid}})">主机管理</a>
                        <a href="#" class="btn dropdown-button waves-effect waves-light "
                           onclick="ldap_user_vpns_edit({{$v.uid}})">VPN管理</a>
                    </td>
                    <td onclick="ldap_del_user(this,{{$v.uid}})">
                        <a a href="#" class="btn dropdown-button waves-effect waves-light ">删除</a>
                    </td>
                </tr>
                {{ end }}
                </tbody>
            </table>
        </div>
    </div>
</div>
<br>


</div>
</div>
<!--end container-->

</section>
<!-- END CONTENT -->

<div id="adduser" class="modal">
    <form role="form">
        <div class="modal-content">
            <div class="row">
                <p>
                    <strong>添加用户</strong>
                </p>
            </div>
            <div class="row">

                <div class="input-field col s4">
                    <input type="text" name="uid" id="uid">
                    <label for="uid">用户名(UID)</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="givenName" id="givenName">
                    <label for="givenName">姓</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="sn" id="sn">
                    <label for="sn">名</label>
                </div>

            </div>
            <div class="row">

                <div class="input-field col s4">
                    <label></label>
                    <select name="gidNumber" id="gidNumber">
                        <option value="" disabled selected>选择用户组</option>
                        {{ range $k,$v :=$.LdapGroupAll}}
                        <option value="{{$v.gidNumber}}">{{$v.description}}</option>
                        {{ end }}
                    </select>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="mobile" id="mobile">
                    <label for="mobile">电话</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="mail" id="mail">
                    <label for="mail">邮箱</label>
                </div>

            </div>

        </div>

        <div class="modal-footer">
            <a class="waves-effect waves-red btn-flat modal-action modal-close">关闭</a>
            <a class="waves-effect waves-green btn-flat modal-action" onclick="ldap_add_user()">
                保存
            </a>
        </div>
    </form>
</div>

<div id="edituser" class="modal">
    <form role="form">
        <div class="modal-content">
            <div class="row">
                <p>
                    <strong>编辑用户</strong>
                </p>
            </div>
            <div class="row">

                <div class="input-field col s4">
                    <input type="text" name="edit_uid" id="edit_uid" disabled value=" ">
                    <label for="edit_uid" class="active">用户名(UID)禁止修改</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="edit_givenName" id="edit_givenName" value=" ">
                    <label for="edit_givenName" class="active">姓</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="edit_sn" id="edit_sn" value=" ">
                    <label for="edit_sn" class="active">名</label>
                </div>

            </div>
            <div class="row">


                <div class="input-field col s4">
                    <label></label>
                    <select name="edit_gidNumber" id="edit_gidNumber">
                        <option value="" selected disabled>选择用户组</option>
                        <option value="0">不加入任何组</option>
                        {{ range $k,$v :=$.LdapGroupAll}}
                        <option value="{{$v.gidNumber}}">{{$v.description}}</option>
                        {{ end }}
                    </select>
                </div>

                <div class="input-field col s4">
                    <input type="text" name="edit_mobile" id="edit_mobile" value=" ">
                    <label for="edit_mobile" class="active">电话</label>
                </div>
                <div class="input-field col s4">
                    <input type="text" name="edit_mail" id="edit_mail" value=" ">
                    <label for="edit_mail" class="active">邮箱</label>
                </div>

            </div>

        </div>

        <div class="modal-footer">
            <a class="waves-effect waves-red btn-flat modal-action modal-close">关闭</a>
            <a class="waves-effect waves-green btn-flat modal-action" onclick="ldap_user_edit_post()">
                保存
            </a>
        </div>
    </form>
</div>


<div id="sshkey" class="modal">
    <form role="form">
        <div class="modal-content">
            <div class="row">
                <p>
                    <strong>SSHKEY管理</strong>
                </p>

            </div>
            <div class="row">

                <div class="input-field col s12" style="display: none">
                    <input type="text" name="edit_uid_sshkey" id="edit_uid_sshkey" disabled value=" ">
                    <label for="edit_uid_sshkey" class="active">用户名(UID)禁止修改</label>
                </div>


                <div class="input-field col s12">

                   <textarea style="height: 200px;resize:none" rows="50" type="text" id="message"
                             name="message" length="1200">
                            </textarea>

                </div>

            </div>

        </div>

        <div class="modal-footer">
            <a class="waves-effect waves-red btn-flat modal-action modal-close">关闭</a>
            <a class="waves-effect waves-green btn-flat modal-action" onclick="ldap_user_sshkey_post()">
                保存
            </a>
        </div>
    </form>
</div>


<div id="user_host" class="modal">
    <form role="form">
        <div class="modal-content">

            <div class="row">
                <p>
                    <strong>添加用户主机登录权限</strong>
                </p>

            </div>

            <div class="row">

                <div class="input-field col s4">
                    <input type="text" name="uid_user_host" id="uid_user_host" disabled value=" ">
                    <label for="uid_user_host" class="active">用户名(UID)</label>
                </div>

                <div class="col s12 m8 l6">
                    <div class="input-field col s12">
                        <select id="add_hostname" name="add_hostname">
                            <option value="" selected disabled>选择需要添加的主机</option>
                            <option value="all">all</option>
                            {{ range $k,$v :=$.HostAll}}
                            <option value="{{$v.id}}">{{$v.id}}</option>
                            {{ end }}
                        </select>
                    </div>
                </div>

                <div class="col s12 m8 l2">
                    <a class="btn dropdown-button waves-effect waves-light " onclick="ldap_user_add_host()">添加</a>
                </div>

            </div>

            <div class="row">
                <p>
                    <strong>拥有主机列表</strong>
                </p>
            </div>

            <div class="row">
                <div class="col s12 m8 l12">
                    <table class="bordered" id="hostlist">
                        <thead>
                        <tr>
                            <th data-field="id">列表</th>
                            <th data-field="id">删除</th>
                        </tr>
                        </thead>
                        <tbody id="ioioi">
                        </tbody>
                    </table>
                </div>
            </div>

        </div>

        <div class="modal-footer">
            <a class="waves-effect waves-red btn-flat modal-action modal-close">关闭</a>
        </div>
    </form>
</div>

<div id="user_vpn" class="modal">
    <form role="form">
        <div class="modal-content">
            <div class="row">
                <p>
                    <strong>添加用户VPN权限</strong>
                </p>

            </div>
            <div class="row">

                <div class="input-field col s4">
                    <input type="text" name="uid_user_vpn" id="uid_user_vpn" disabled value=" ">
                    <label for="uid_user_vpn" class="active">用户名(UID)</label>
                </div>

                <div class="col s12 m8 l6">
                    <div class="input-field col s12">
                        <select id="add_vpn" name="add_vpn">
                            <option value="" selected disabled>选择需要添加的VPN</option>
                            <option value="all">all</option>
                            {{ range $k,$v :=$.VpNListAll}}
                            <option value="{{$v.vpn_labelling}}">{{$v.vpn_name}}</option>
                            {{ end }}
                        </select>
                    </div>
                </div>

                <div class="col s12 m8 l2">
                    <a class="btn dropdown-button waves-effect waves-light " onclick="ldap_post_add_vpn()">添加</a>
                </div>

            </div>

            <div class="row">
                <p>
                    <strong>拥有VPN权限列表</strong>
                </p>
            </div>

            <div class="row">
                <div class="col s12 m8 l12">
                    <table class="bordered" id="vpnlist">
                        <thead>
                        <tr>
                            <th data-field="id">列表</th>
                            <th data-field="id">删除</th>
                        </tr>
                        </thead>
                        <tbody id="vpnlist_value">
                        </tbody>
                    </table>
                </div>
            </div>

        </div>

        <div class="modal-footer">
            <a class="waves-effect waves-red btn-flat modal-action modal-close">关闭</a>
        </div>
    </form>
</div>
{{ template "foot" .Global}}
<script type="text/javascript" src="/statics/js/function.js"></script>
<!-- jQuery Library -->
<script type="text/javascript" src="/statics/js/plugins/jquery-1.11.2.min.js"></script>
<!--materialize js-->
<script type="text/javascript" src="/statics/js/materialize.min.js"></script>
<!--prism-->
<script type="text/javascript" src="/statics/js/plugins/prism/prism.js"></script>
<!--scrollbar-->
<script type="text/javascript" src="/statics/js/plugins/perfect-scrollbar/perfect-scrollbar.min.js"></script>
<!-- data-tables -->
<script type="text/javascript" src="/statics/js/plugins/data-tables/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/statics/js/plugins/data-tables/data-tables-script.js"></script>
<!-- chartist -->
<script type="text/javascript" src="/statics/js/plugins/chartist-js/chartist.min.js"></script>
<!--sweetalert -->
<script type="text/javascript" src="/statics/js/plugins/sweetalert/sweetalert.min.js"></script>
<!--plugins.js - Some Specific JS codes for Plugin Settings-->
<script type="text/javascript" src="/statics/js/plugins.min.js"></script>
<!--custom-script.js - Add your own theme custom JS-->
<script type="text/javascript" src="/statics/js/custom-script.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $(".dropdown-content.select-dropdown li").on("click", function () {
            var that = this;
            setTimeout(function () {
                if ($(that).parent().hasClass('active')) {
                    $(that).parent().removeClass('active');
                    $(that).parent().hide();
                }
            }, 100);
        });
    });

</script>
</body>

</html>